package com.xiaoxi.open.design.behavioral.chainofresponsibilitypattern.service.password;

import com.xiaoxi.open.design.behavioral.chainofresponsibilitypattern.domain.password.CheckResult;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

/**
 * @ClassName ContainUserNameCheck
 * @Description
 * @Author xiaoxi
 * @Date 2022/7/11 21:49
 * @Version 1.0
 */
@Component
public class ContainUserNameCheck extends AbstractCheckPassword {

    private String userName;

    public ContainUserNameCheck() {
    }

    public ContainUserNameCheck(String userName) {
        this.userName = userName;
    }

    @Override
    public void doHandler(String password, CheckResult checkResult) throws Exception {
        if (StringUtils.isNotBlank(userName)) {
            if (password.toLowerCase().contains(this.userName.toLowerCase())) {
                checkResult.getErrorReason().add("密码不应包含用户名信息");
            }
        }
    }
}
